using MicroMsg.Manager;
using MicroMsg.Scene;
using MicroMsg.Storage;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
namespace MicroMsg.UI.UserContrl
{
	public class ChatEggsCtrl : UserControl
	{
		public enum EggType
		{
			ReceiveEgg,
			SendEgg
		}
		private const string TAG = "ChatEggsCtrl";
		private const int WEAVE_COUNT = 9;
		private const string birthdayEmojiCode = "7oySIO6MriAgICDujYvujYsgICAgIO6MkgogICAgICAgICDilI/ugYbugYbugYbilJMg7oyuCiAgICAgICAgICDujYvujYsg7o2L7o2LCu6MruKUj+KUge6Nh+6Nh+6Nh+KUgeKUkwogICAgIO6Ni+6Ni+6Ni+6Ni+6Ni+6Niw==";
		private Random _random = new Random();
		private int _weaveCount;
		private DispatcherTimer _dt = new DispatcherTimer();
		private List<int> _emojiIndexList;
		private ChatEggsLineItem[] mapItems;
		private List<EmojiArt> currentEmojiArtList = new List<EmojiArt>();
		internal Canvas ChatEggsPannel;
		private bool _contentLoaded;
		public ChatEggsCtrl()
		{
			base.set_Visibility(1);
			this.InitializeComponent();
		}
		public void startChatEggs(List<EggItem> eggItemList, ChatEggsCtrl.EggType eggType)
		{
			this._emojiIndexList = new List<int>();
			using (List<EggItem>.Enumerator enumerator = eggItemList.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					EggItem current = enumerator.get_Current();
					int emojiPos = EmojiManager.GetInstance().getEmojiPos(current.emoji.ToCharArray()[0]);
					if (emojiPos > 0)
					{
						if (eggType == ChatEggsCtrl.EggType.ReceiveEgg)
						{
							ServiceCenter.statReportMgr.addStatItem(enKVStatKey.MM_RECEIVERINCITATIONCOLOREGG, string.Format("{0},{1}", current.reportType, 1));
						}
						else
						{
							if (eggType == ChatEggsCtrl.EggType.SendEgg)
							{
								ServiceCenter.statReportMgr.addStatItem(enKVStatKey.MM_SENDERINCITATIONCOLOREGG, string.Format("{0},{1}", current.reportType, 1));
							}
						}
						this._emojiIndexList.Add(emojiPos);
					}
				}
			}
			if (this._emojiIndexList.get_Count() > 0)
			{
				base.set_Visibility(0);
				this._weaveCount = 0;
				if (this._dt.get_IsEnabled())
				{
					this._dt.Stop();
					this._dt.remove_Tick(new EventHandler(this.dt_Tick));
				}
				this._dt.set_Interval(new TimeSpan(0, 0, 0, 0, 500));
				this._dt.add_Tick(new EventHandler(this.dt_Tick));
				this._dt.Start();
			}
		}
		private void dt_Tick(object sender, EventArgs e)
		{
			this.PlayStoryboard();
			this._weaveCount++;
			if (this._weaveCount <= 9)
			{
				this._dt.set_Interval(new TimeSpan(0, 0, 0, 0, 200 + this._weaveCount * 100));
				return;
			}
			this._dt.Stop();
			this._dt.remove_Tick(new EventHandler(this.dt_Tick));
		}
		private void PlayStoryboard()
		{
			int num = this._random.Next(6, 8);
			List<Storyboard> list = new List<Storyboard>();
			for (int i = 0; i < num; i++)
			{
				Image image = new Image();
				Image arg_6B_0 = image;
				BitmapImage bitmapImage = new BitmapImage();
				bitmapImage.set_UriSource(new Uri(string.Format("/MicroMsg;component/Resource/Img/emoji/{0}.png", this._emojiIndexList.get_Item(this._random.Next(0, this._emojiIndexList.get_Count()))), 2));
				arg_6B_0.set_Source(bitmapImage);
				image.set_Stretch(0);
				image.set_RenderTransform(new CompositeTransform());
				image.set_Projection(new PlaneProjection());
				Image image2 = image;
				Storyboard storyboard = new Storyboard();
				DoubleAnimation doubleAnimation = new DoubleAnimation();
				doubleAnimation.set_Duration(new TimeSpan(0, 0, 3));
				doubleAnimation.set_From(new double?((double)this._random.Next(0, 100)));
				doubleAnimation.set_To(new double?(800.0));
				DoubleAnimation doubleAnimation2 = doubleAnimation;
				Storyboard.SetTargetProperty(doubleAnimation2, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateY)", new object[0]));
				Storyboard.SetTarget(doubleAnimation2, image2);
				DoubleAnimation arg_13C_0 = doubleAnimation2;
				BackEase backEase = new BackEase();
				backEase.set_Amplitude((double)this._random.Next(0, 7) / 10.0);
				backEase.set_EasingMode(1);
				arg_13C_0.set_EasingFunction(backEase);
				storyboard.get_Children().Add(doubleAnimation2);
				int num2 = this._random.Next(0, 360);
				DoubleAnimation doubleAnimation3 = new DoubleAnimation();
				doubleAnimation3.set_Duration(new TimeSpan(0, 0, 3));
				doubleAnimation3.set_From(new double?((double)num2));
				doubleAnimation3.set_To(new double?((double)num2 * (this._random.NextDouble() * 2.0 - 1.0) + (double)num2));
				DoubleAnimation doubleAnimation4 = doubleAnimation3;
				Storyboard.SetTargetProperty(doubleAnimation4, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationZ)", new object[0]));
				Storyboard.SetTarget(doubleAnimation4, image2);
				storyboard.get_Children().Add(doubleAnimation4);
				double num3 = (double)this._random.Next(5, 13) / 10.0;
				double num4 = this._random.NextDouble();
				DoubleAnimation doubleAnimation5 = new DoubleAnimation();
				doubleAnimation5.set_Duration(new TimeSpan(0, 0, 3));
				doubleAnimation5.set_From(new double?(num3));
				doubleAnimation5.set_To(new double?(num3 + num4));
				DoubleAnimation doubleAnimation6 = doubleAnimation5;
				Storyboard.SetTargetProperty(doubleAnimation6, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.ScaleX)", new object[0]));
				Storyboard.SetTarget(doubleAnimation6, image2);
				storyboard.get_Children().Add(doubleAnimation6);
				DoubleAnimation doubleAnimation7 = new DoubleAnimation();
				doubleAnimation7.set_Duration(new TimeSpan(0, 0, 3));
				doubleAnimation7.set_From(new double?(num3));
				doubleAnimation7.set_To(new double?(num3 + num4));
				DoubleAnimation doubleAnimation8 = doubleAnimation7;
				Storyboard.SetTargetProperty(doubleAnimation8, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.ScaleY)", new object[0]));
				Storyboard.SetTarget(doubleAnimation8, image2);
				storyboard.get_Children().Add(doubleAnimation8);
				double num5 = (double)this._random.Next(0, 448);
				DoubleAnimation doubleAnimation9 = new DoubleAnimation();
				doubleAnimation9.set_Duration(new TimeSpan(0, 0, 3));
				doubleAnimation9.set_From(new double?(num5));
				doubleAnimation9.set_To(new double?(num5 + (double)this._random.Next(0, 400) - 200.0));
				DoubleAnimation doubleAnimation10 = doubleAnimation9;
				Storyboard.SetTargetProperty(doubleAnimation10, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateX)", new object[0]));
				Storyboard.SetTarget(doubleAnimation10, image2);
				DoubleAnimation arg_3AF_0 = doubleAnimation10;
				BackEase backEase2 = new BackEase();
				backEase2.set_Amplitude((double)this._random.Next(0, 7) / 10.0);
				backEase2.set_EasingMode(1);
				arg_3AF_0.set_EasingFunction(backEase2);
				storyboard.get_Children().Add(doubleAnimation10);
				DoubleAnimation doubleAnimation11 = new DoubleAnimation();
				doubleAnimation11.set_Duration(new TimeSpan(0, 0, 1));
				doubleAnimation11.set_From(new double?(this._random.NextDouble()));
				doubleAnimation11.set_To(new double?(1.0));
				DoubleAnimation doubleAnimation12 = doubleAnimation11;
				Storyboard.SetTargetProperty(doubleAnimation12, new PropertyPath("(UIElement.Opacity)", new object[0]));
				Storyboard.SetTarget(doubleAnimation12, image2);
				storyboard.get_Children().Add(doubleAnimation12);
				storyboard.add_Completed(new EventHandler(this.OneElement_Completed));
				list.Add(storyboard);
				this.ChatEggsPannel.get_Children().Add(image2);
			}
			this.ChatEggsPannel.UpdateLayout();
			list.get_Item(list.get_Count() - 1).add_Completed(new EventHandler(this.OneWive_Completed));
			using (List<Storyboard>.Enumerator enumerator = list.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					Storyboard current = enumerator.get_Current();
					current.Begin();
				}
			}
		}
		private void OneElement_Completed(object sender, EventArgs e)
		{
			try
			{
				this.ChatEggsPannel.get_Children().RemoveAt(0);
			}
			catch
			{
			}
		}
		private void OneWive_Completed(object sender, EventArgs e)
		{
			if (this._weaveCount - 1 > 9)
			{
				base.set_Visibility(1);
			}
		}
		public void DoLoad()
		{
			if (this.currentEmojiArtList != null && this.currentEmojiArtList.get_Count() > 0)
			{
				if (this.mapItems == null)
				{
					this.mapItems = new ChatEggsLineItem[this.currentEmojiArtList.get_Count()];
				}
				for (int i = 0; i < this.currentEmojiArtList.get_Count(); i++)
				{
					EmojiArt emojiArt = this.currentEmojiArtList.get_Item(i);
					if (emojiArt != null)
					{
						this.mapItems[i] = new ChatEggsLineItem(i == this.currentEmojiArtList.get_Count() - 1);
						this.mapItems[i].add_Click(new RoutedEventHandler(this.newItem_Click));
						if (i == 0)
						{
							this.mapItems[i].InitData(emojiArt, null, new EventHandler(this.firstAniToShow_Completed));
						}
						else
						{
							this.mapItems[i].InitData(emojiArt, this.mapItems[i - 1], null);
						}
						this.ChatEggsPannel.get_Children().Add(this.mapItems[i]);
					}
				}
				return;
			}
		}
		private void firstAniToShow_Completed(object sender, EventArgs e)
		{
			if (e != null)
			{
				this.mapItems = null;
				base.set_Visibility(1);
				return;
			}
			if (this.mapItems == null)
			{
				return;
			}
			for (int i = 0; i < this.currentEmojiArtList.get_Count(); i++)
			{
				this.mapItems[i].flashEggs();
			}
		}
		public bool InitEmojiList(int packId, int index)
		{
			this.ChatEggsPannel.get_Children().Clear();
			if (Enumerable.Count<EmojiArt>(this.currentEmojiArtList) <= 0)
			{
				this.currentEmojiArtList.Clear();
				string text = NetSceneGetPackageList.decodeBase64("UTF-8", "7oySIO6MriAgICDujYvujYsgICAgIO6MkgogICAgICAgICDilI/ugYbugYbugYbilJMg7oyuCiAgICAgICAgICDujYvujYsg7o2L7o2LCu6MruKUj+KUge6Nh+6Nh+6Nh+KUgeKUkwogICAgIO6Ni+6Ni+6Ni+6Ni+6Ni+6Niw==");
				string[] array = text.Split(new char[]
				{
					'\n'
				});
				string[] array2 = array;
				for (int i = 0; i < array2.Length; i++)
				{
					string strEmojiArt = array2[i];
					EmojiArt emojiArt = new EmojiArt();
					emojiArt.strEmojiArt = strEmojiArt;
					this.currentEmojiArtList.Add(emojiArt);
				}
			}
			this.DoLoad();
			return true;
		}
		private void newItem_Click(object sender, RoutedEventArgs e)
		{
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Chat/ChatEggsCtrl.xaml", 2));
			this.ChatEggsPannel = (Canvas)base.FindName("ChatEggsPannel");
		}
	}
}
